elastic search|April 09, 2018|1 min read

ElasticSearch: Validation Failed: 1: script or doc is missing

TL;DR

This error occurs when using POST instead of PUT for updates, or missing the doc wrapper. Use _update endpoint with a doc object containing your fields.

ElasticSearch: Validation Failed: 1: script or doc is missing

While dealing with ELastic Search documents, you faced this issue while updating document:

ElasticSearch: Validation Failed: 1: script or doc is missing;

Reason

When you insert documents to ElasticSearch, you write something like: ``` { index: 'your_index_name', type: 'your_type', body: { title: 'this is my sample title', createdAt: 'some_date' }, refresh: true } ```

But, when you want to update the documents. There is a slight change in json. See example:

{
    index: 'your_index_name',
    type: 'your_type',
    id: 'document_id',
    body: {
       doc: {
          title: 'this is my sample title',
          createdAt: 'some_date'
       }
    },
    refresh: true
}

Notice the extra “doc” in there. Generally, users tend to put json without “doc”, and it caused this error.

Enjoy!

Related Posts

Common used Elastic Search queries

Common used Elastic Search queries

Listing down the commonly used Elastic Search queries. You can get search…

ElasticSearch - Update a document and change value of a key

ElasticSearch - Update a document and change value of a key

Thanks for reading.

How to sync Mongodb data to ElasticSearch by using MongoConnector

How to sync Mongodb data to ElasticSearch by using MongoConnector

Introduction This post is about syncing your mongodo database data to…

How to take Backup from MongoDB and Restore to MongoDB

How to take Backup from MongoDB and Restore to MongoDB

This will take backup of your passed database name, to the passed folder. It…

How to connect Php docker container with Mongo DB docker container

How to connect Php docker container with Mongo DB docker container

Goto your command terminal. Type: This will expose port: 27017 by default. You…

Staff Engineer Study Plan for MAANG Interviews — The Complete 12-Week Roadmap

Staff Engineer Study Plan for MAANG Interviews — The Complete 12-Week Roadmap

If you’re a Senior Engineer (L5) preparing for Staff (L6+) roles at MAANG…

Latest Posts

Staff Engineer Study Plan for MAANG Interviews — The Complete 12-Week Roadmap

Staff Engineer Study Plan for MAANG Interviews — The Complete 12-Week Roadmap

If you’re a Senior Engineer (L5) preparing for Staff (L6+) roles at MAANG…

XSS and CSRF Explained — The Complete Guide with Real Attack Examples and Defenses

XSS and CSRF Explained — The Complete Guide with Real Attack Examples and Defenses

XSS and CSRF have been in the OWASP Top 10 for over a decade. They’re among the…

OWASP Top 10 (2021) — Every Vulnerability Explained with Code

OWASP Top 10 (2021) — Every Vulnerability Explained with Code

The OWASP Top 10 is the industry standard for web application security risks. If…

HTTP Cookies Security — Everything Developers Get Wrong

HTTP Cookies Security — Everything Developers Get Wrong

Cookies are the single most important mechanism for web authentication. Every…

Format String Vulnerabilities — The Read-Write Primitive Hiding in printf()

Format String Vulnerabilities — The Read-Write Primitive Hiding in printf()

Format string vulnerabilities are unique in the exploit world. Most memory…

Buffer Overflow Attacks — How Memory Corruption Actually Works

Buffer Overflow Attacks — How Memory Corruption Actually Works

Buffer overflows are the oldest and most consequential vulnerability class in…